/**
 * @description: client
 */

// https://github.com/vitejs/vite/blob/5745a2e8072cb92d647662dc387e7f12b2841cab/packages/vite/src/client/client.ts

const socketHost = `ws://localhost:${+location.port + 1}`
const socket = new WebSocket(socketHost)

socket.open = function () {
  socket.send('233')
}

socket.onmessage = function (event) {
  let data = JSON.parse(event.data)

  switch (data.type) {
    case 'reload':
      window.location.reload()
      break

    default:
      console.log(data)
  }
}

socket.onclose = function () {
  console.log('close')
}
